// 生成侧边栏菜单项
export const generateMenuItems = (router: any) => {
  const menuItems: any[] = []
  
  // 添加顶级路由（包括首页）
  ;(router.routeTree.children as any[])
    .filter((route: any) => !route.path?.includes('/') || route.path === '/') // 包含顶级路由和首页
    .forEach((route: any) => {
      // 更安全地访问元数据
      const meta = route.options && route.options.meta ? route.options.meta : {}
      const item: any = {
        key: route.fullPath || route.path || '',
        path: route.fullPath || route.path || '',
        label: meta.label || route.path || 'Unknown',
        icon: meta.icon || null
      }
      
      // 如果有子路由，添加子菜单
      if (route.children && route.children.length > 0) {
        item.children = route.children.map((childRoute: any) => {
          const childMeta = childRoute.options && childRoute.options.meta ? childRoute.options.meta : {}
          // 使用路由的fullPath作为key和path
          const fullPath = childRoute.fullPath || childRoute.path || ''
          return {
            key: fullPath,
            path: fullPath,
            label: childMeta.label || childRoute.path || 'Unknown',
            icon: childMeta.icon || null
          }
        })
      }
      
      menuItems.push(item)
    })

  return menuItems
}